L1-094 剪切粘贴
题目 L1-094 剪切粘贴
思路分析
代码实现
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
using ll = long long;
using ull = unsigned long long;
using PII = pair<int,int>;
using Pll = pair<ll,ll>;
int dx[4]= {-1,0,1,0},dy[4]= {0,1,0,-1};
const int inf = 0x3f3f3f3f;
int main() {
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
string s;cin>>s;
// int st,ed;cin>>st>>ed;
// st--,ed--;
// int len=ed-st+1;
// cout<<s.substr(st,len);
// string l,r;cin>>l>>r;
// int crl=s.find(l);
// int crr=s.find(r);
// cout<<crl<<" "<<crr;
int n;cin>>n;
while(n--){
int st,ed,len;cin>>st>>ed;
st--,ed--;len=ed-st+1;
string jq=s.substr(st,len);
s.erase(st,len);
string l,r;cin>>l>>r;
int len_l=l.size();
int len_r=r.size();
int zt=s.size();
int s_len=s.size();
for(int i=len_l;i<=s_len-len_r;i++){
if(i-len_l<0) continue;
string pre=s.substr(i-len_l,len_l);
string suf=s.substr(i,len_r);
if(pre==l && suf==r){
zt=i;
break;
}
}
s.insert(zt,jq);
}
cout<<s;
return 0;
}
同类题型
视频讲解
⬅️ L1-093 猜帽子游戏 🏠 00-天梯赛 ➡️ L1-095 分寝室
💬 评论